<template>
	<view>
		<view class="alldiv">
			<view class="headdiv">
				<van-icon name="arrow-left" class="back" @click="returns" />
				<map style="width: 100%;height: 100%;" :latitude="latitude" :longitude="longitude" :markers="covers">
				</map>
			</view>

			<view class="bodydiv">
				<!-- 订单信息 -->
				<view class="order-info">
					<view class="title">
						{{ language.FreeRide.cancelTrip }}
					</view>
					<view class="tip">
						{{ cancelTime }}{{ language.FreeRide.activeCancellation }}
					</view>
				</view>
				
				<!-- 地址信息 -->
				<view class="address-box" v-show="startAddress">
					<view class="date" v-show="goTime">
						<u-icon style="margin-right: 16rpx;" name="clock-fill" size="12"></u-icon>
						{{ goTime }}
					</view>
					<view class="origin-station">
						<text class="van-ellipsis">{{ startAddress }}</text>
					</view>
					<view class="destination">
						<text class="van-ellipsis">{{ endAddress }}</text>
					</view>
					<view class="carpool-details">
						<view class="people-num">
							{{ passengers }} {{ language.FreeRide.people }}
						</view>
						<!-- <view class="line"></view>
						<view class="state">
							{{ language.FreeRide.noPiece }}
						</view> -->
					</view>
				</view>

				<!-- 帮助 -->
				<view class="other-use">
					<view class="other-use-item" v-for="item in otherUseList" :key="item.id">
						<u-icon :name="item.icon" size="12"></u-icon>
						<view class="name">{{ item.name }}</view>
					</view>
				</view>
				
				<!-- 重新预约行程 -->
				<view class="takeNewTaxi">
					<u-button class="takeNewTaxi-btn" @click="takeTaxiNew" shape="square">{{ language.FreeRide.rescheduleTrip }}</u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { getTaxiOrder } from '@/api/driver'
	export default {
		data() {
			return {
				latitude:{},
				latitude: 39.909,
				longitude: 116.39742,
				covers: [{
						latitude: 39.909,
						longitude: 116.39742,
						iconPath: "../../../static/location.png",
					},
					{
						latitude: 39.9,
						longitude: 116.39,
						iconPath: "../../../static/location.png",
					},
				],
				profilePhoto: require('@/static/image/BankCard.png'),
				otherUseList: [
					{
						id: 1,
						icon: require('@/static/image/path.png'),
						name: '投诉反馈',
					},{
						id: 0,
						icon: require('@/static/image/seek-help.png'),
						name: '紧急求助',
					},
					{
						id: 2,
						icon: require('@/static/image/share.png'),
						name: '联系客服',
					},
				],
				orderId: 0,
				goTime: '',
				startAddress: '',
				endAddress: '',
				passengers: '',
				cancelTime: ''
			}
		},
		onLoad(option) {
			if (!option.id) {
				this.returns()
			}
			this.orderId = option.id
			this.getlanguagedata();
			this.getOrder();
		},
		methods: {
			getlanguagedata() {
			  this.language =
			    this.$store.getters["internationalization/getinternationalization"];
			},
			takeTaxiNew() {
				uni.navigateTo({
					url: "/pages/Home/freeRide/freeRideNow",
				});
			},
			returns() {
				uni.navigateTo({
					url: "/pages/Home/freeRide/freeRideNow",
				});
			},
			async getOrder() {
				try {
					await getTaxiOrder({id: this.orderId}).then(res => {
						if (res.code === 0) {
							if (res.data?.planStartTime && res.data?.planEndTime) {
								this.goTime = this.convertDateString(res.data?.planStartTime) + ' - ' + this.convertDateString(res.data?.planEndTime)
							}
							this.startAddress = res.data.startPlace;
							this.endAddress = res.data.endPlace;
							this.passengers = res.data.passengers || 1;
							this.cancelTime = this.convertDate(res.data.endTime);
						}
					})
				} catch (error) {
					console.log(error)
				}
			},
			// 出发日期格式化
			convertDateString(dateString) {
				// 使用正则表达式提取日期和时间部分
				const [datePart, timePart] = dateString?.split(' ');
				const [year, month, day] = datePart?.split('-');
				const [hours, minutes] = timePart?.split(':');
				
				// 格式化为目标格式
				return `${year}${this.language?.FreeRide.year}${month}${this.language?.FreeRide.month}${day}${this.language?.FreeRide.day} ${hours}:${minutes}`;
			},
			// 取消日期格式化
			convertDate(dateString) {
				if (!dateString) return '';
				let today = new Date();
				let tomorrow = new Date();
				tomorrow.setDate(today.getDate() + 1);
				// 将时间设置为 00:00:00
				tomorrow.setHours(0, 0, 0, 0);
				const tomorrowTime = tomorrow.getTime() // 明天凌晨
				tomorrow.setDate(tomorrow.getDate() + 1)
				const tomorrowTime2 = tomorrow.getTime() // 后天凌晨
				tomorrow.setDate(tomorrow.getDate() + 1)
				const tomorrowTime3 = tomorrow.getTime() // 大后天凌晨
				const nowTime = new Date(dateString).getTime()

				const [datePart, timePart] = dateString?.split(' ');
				const [hours, minutes] = timePart?.split(':');
				if (nowTime < tomorrowTime) {
					return `${this.language.FreeRide.timeList[0]}${hours}:${minutes}`
				} else if (nowTime < tomorrowTime2) {
					return `${this.language.FreeRide.timeList[1]}${hours}:${minutes}`
				} else if (nowTime < tomorrowTime3) {
					return `${this.language.FreeRide.timeList[2]}${hours}:${minutes}`
				} else {
					return `${datePart} ${hours}:${minutes}`
				}
			},
		}
	}
</script>

<style lang="less" scoped>
	.alldiv {
		width: 100%;
		height: 100vh;

		.headdiv {
			position: relative;
			width: 100%;
			height: 620rpx;
			overflow: hidden;

			.back {
				position: absolute;
				top: 100rpx;
				left: 32rpx;
				z-index: 99;
				font-size: 34rpx;
			}
		}

		.bodydiv {
			// margin-top: -20rpx;
			padding: 48rpx 32rpx;
			width: 100%;
			height: calc(100vh - 600rpx);
			border-radius: 20px 20px 0 0;
			background: rgba(255, 255, 255, 1);
			box-shadow: 0px -3px 6px rgba(6, 145, 161, 0.05);
			overflow-y: auto;

			// 订单信息
			.order-info {
				.title {
					font-size: 32rpx;
					font-weight: bold;
					line-height: 44rpx;
					color: rgba(56, 56, 56, 1);
				}

				.tip {
					margin-top: 8rpx;
					font-size: 20rpx;
					line-height: 28rpx;
					color: rgba(153, 153, 153, 1);
				}
			}
			
			// 地址信息
			.address-box {
				margin-top: 20rpx;
				border-radius: 16px;
				background: rgb(255, 255, 255);
				box-shadow: 0px 2px 4px rgba(5, 48, 7, 0.1);
				padding: 28rpx 24rpx;
				font-size: 24rpx;
				line-height: 32rpx;
				color: rgba(102, 102, 102, 1);

				.date {
					display: flex;
					align-items: center;
				}
				
				.origin-station {
					position: relative;
					display: flex;
					align-items: center;
					margin: 12rpx 0;
					&::before {
						content: '';
						display: block;
						margin: 0 20rpx 0 6rpx;
						width: 6px;
						height: 6px;
						border-radius: 50%;
						background: rgb(47, 212, 184);
					}
					
					&::after {
						position: absolute;
						left: 10rpx;
						top: 28rpx;
						content: '';
						display: block;
						height: 20rpx;
						width: 2rpx;
						background: rgb(217, 219, 218);;
					}
				}
				
				.destination {
					display: flex;
					align-items: center;
					
					&::before {
						content: '';
						display: block;
						margin: 0 20rpx 0 3px;
						width: 6px;
						height: 6px;
						border-radius: 50%;
						background: rgb(255, 141, 26)
					}
				}
				
				.carpool-details {
					margin-top: 12rpx;
					display: flex;
					align-items: center;
					padding-left: 40rpx;
					.line {
						margin: 0 10rpx;
						width: 2rpx;
						height: 24rpx;
						background: rgba(102, 102, 102, 1);
					}
				}
			}

			.mr10 {
				margin-right: 20rpx;
			}

			// 其他操作
			.other-use {
				display: flex;
				justify-content: center;
				margin: 40rpx 0;

				.other-use-item {
					display: flex;
					flex-direction: column;
					align-items: center;
					justify-content: center;
					width: 184rpx;
					padding: 0 0;
					border-radius: 8rpx;
					background: rgb(255, 255, 255);

					.name {
						margin-top: 8rpx;
						color: rgba(102, 102, 102, 1);
						font-size: 24rpx;
						line-height: 32rpx;
					}
				}
			}
			
			.takeNewTaxi {
				position: fixed;
				bottom: 0;
				left: 0;
				width: 100%;
				height: 236rpx;
				padding: 48rpx 70rpx;
				border-radius: 20px 20px 0px 0px;
				background: rgb(255, 255, 255);
				box-shadow: 0px -3px 6px rgba(5, 48, 7, 0.08);
				
				.takeNewTaxi-btn {
					height: 88rpx;
					border-radius: 60rpx;
					background: linear-gradient(90deg, rgb(65, 240, 135) 0%, rgb(47, 212, 184) 100%);
					box-shadow: 0px -3px 6px rgba(5, 48, 7, 0.08);
					color: #fff;
					font-size: 32rpx;
					font-weight: bold;
				}
			}
		}
	}
</style>